#!/usr/bin/python
# -*- coding: utf-8 -*-

# def fun1():
#     return 200
# print(fun1)
# print(fun1())
#
# #lambda 表达式
# #1/没有参数
# fun2 = lambda :200
# print(fun2)
# print(fun2())
#
# #2/有参数
# fun3 = lambda a, b:a + b
# print(fun3)
# print(fun3(1, 2))
#
# fun4 = lambda a, b, c = 100:a + b + c
# print(fun4(1, 2))

#
#
# fun1 = lambda *args:args
# print(fun1)
# print(fun1(1, 2, 3))
#
#
# fun3 = lambda a, b:a if a>b else b
# print(fun3(1000, 500))
#
#
# students = [ {'name': 'TOM', 'age': 20}, {'name': 'ROSE', 'age': 19}, {'name': 'Jack', 'age': 22} ]
# #按name值升序排列
# students.sort(key = lambda x : x ['name'])
# print(students)
# #按name值降序排列
# students.sort(key = lambda x : x ['name'], reverse= True)
# print(students)
# #按age值升序排列
# students.sort(key = lambda x : x ['age'])
# print(students)


#####高阶函数############
#绝对值
# print(abs(-10))
# #round四舍五入
# print(round(1.495))

#求绝对值的和
#方法一
# def add(a, b):
#     return abs(a) + abs(b)
#
# print(add(10, -10))
#
# #方法二：
# def add_01(a, b, c):
#     return c(a) + c(b)
#
# print(add_01( -10, 20, abs))
# #求两个数四舍五入后的和
# print(add_01(1.2, 1.8, round))

#需求:计算list1序列中各个数字的2次方。
#高阶函数   map()
# list1 = [1, 2, 3, 4, 5]
# def fun1(x):
#     return x ** 2
# res = map(fun1, list1)
# print(res)
# print(list(res))

# import functools
#
# list1 = [1, 2, 3, 4, 5]
# def fun2(a, b):
#     return a + b
#
# res = functools.reduce(fun2, list1)
# print(res)


# list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# def fund(x):
#     return x % 2 == 0
#
# res = filter(fund, list1)
# print(res)
# print(list(res))

#递归
def sum_number(num):
    #如果是1，直接返回1
    if num == 1:
        return 1
    return num + sum_number(num - 1)

res = sum_number(3)
print(res)